import { defineConfig } from 'vite'
import path from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { autoComplete, Plugin as importToCDN } from "vite-plugin-cdn-import"

export default defineConfig({
	base: './',
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
		visualizer({
			emitFile: false,
			filename: 'stats.html',
			open: true,
			sourcemap: true
		}),
		importToCDN({
			modules: [
				// {
				// 	name: "element-plus",
				// 	var: "ElementPlus",
				// 	path: "//cdn.jsdelivr.net/npm/element-plus@2.8.1/dist/index.full.min.js",
				// 	css: "//cdn.jsdelivr.net/npm/element-plus@2.8.1/dist/index.min.css"
				// },
				// {
				// 	name: "fabric-with-erasing",
				// 	var: "FabricWithErasing",
				// 	path: "//cdn.jsdelivr.net/npm/fabric-with-erasing@1.0.1/dist/fabric.min.js"
				// },
				// autoComplete('axios'),
				// autoComplete('vue')
			]
		})
	],
	resolve: {
		alias: [{
			find: '@', // 根目录
			replacement: path.resolve(__dirname, 'src'),
		}, ],
		extensions: ['.js', '.vue', '.json', '.ts'],
	},
	server: {
		host: '127.0.0.1',
		proxy: {
			'/api': {
				target: 'https://api.visualx.art',
				//target: 'http://127.0.0.1:8080',
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api/, ''),
			},
		},
	}
})